package com.lihao.sam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.sam.dao.AccommodationFeeCollectionDao;
import com.lihao.sam.dao.CollectionPaymentOtherExpensesDao;
import com.lihao.sam.entity.xiaobei.AccommodationFeeCollection;
import com.lihao.sam.entity.xiaobei.CollectionPaymentOtherExpenses;
import com.lihao.sam.service.intf.AccommodationFeeCollectionService;
import com.lihao.sam.service.intf.CollectionPaymentOtherExpensesService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yifu
 * @date2022/11/22 19:51
 */
@Service
public class CollectionPaymentOtherExpensesServiceImpl implements CollectionPaymentOtherExpensesService {

    @Resource
    private CollectionPaymentOtherExpensesDao dao;
    @Override
    public R add(CollectionPaymentOtherExpenses collectionPaymentOtherExpenses) {
        //1.校验参数
        if(collectionPaymentOtherExpenses!=null){
            //2.操作数据库
            if(dao.add(collectionPaymentOtherExpenses)>0){
                return R.ok();
            }
        }
        return R.fail();
        }

    @Override
    public R update(CollectionPaymentOtherExpenses collectionPaymentOtherExpenses) {
        //1.校验参数
        if(collectionPaymentOtherExpenses!=null){
            //2.操作数据库
            if(dao.update(collectionPaymentOtherExpenses)>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R delete(int id) {
        //1.校验参数
        if(id>0){
            //2.操作数据库
            if(dao.delete(id)>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R delBatch(int[] array) {
        if (dao.delBatch(array) > 0) {
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public PageVo queryPage(String studentid,String afname, String college, int page, int limit) {
        //1.开启分页，设置对应的页码
        PageHelper.startPage(page,limit);
        //2.开始查询
        PageInfo<CollectionPaymentOtherExpenses> pageInfo=new PageInfo<>(dao.selectByWhere(studentid, afname,college));
        //3.返回对应的结果
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }


}
